console.log($.cookie('shopcart'))
$(function(){
    $('.order-detail').click(function(){
        $('.order-produce').toggle(1500)
    })
    var shopCart = JSON.parse($.cookie('shopcart'))
   
    var strHtml = ''
    var sumPrice = 0;
    var sumCount = 0;
    var allp = []

    arrAllProducts.forEach(function(item){
        allp = allp.concat(item.products)
    })
    shopCart.forEach(function(item){
        var temProduct = allp.find(function(p){
            return p.id == item.pid
        })
        sumPrice += item.price * item.count;
        sumCount +=item.count;
        strHtml +=
        `
        <div class="o-p-item"> 
        <ul>
        <li><img class="o-p-img" src="${temProduct.img}" alt="${temProduct.img}"></li>
        <li>${temProduct.name}</li>
        <li class="o-p-price"><em>${item.price.toFixed(2)}</em>X${item.count}</li>
        </ul>
        </div>
        `


    })
    $('.order-produce').html(strHtml);
    $('#orderPrice').text(sumPrice.toFixed(2))

    var orders = []
    if(localStorage.orders){
        orders = JSON.parse(localStorage.orders);
    }
})
    $('#btnSub').click(function(){
        var order = {};
        order.oid = Date.now();
        var name = $('#txtName').val();
        var mobile = $('#txtMoblie').val();
        var address = $('#txtAddress').val();
        var remarks = $('#txtRemarks').val();

        if(name && mobile && address){
            order.receiver = name;
            order.mobile = mobile;
            order.address = address;
            order.remarks = remarks;
            order.plist = shopCart;
        }else{
            alert('请输入购买人的详细信息');
            return
        }
        orders.push(order);
        localStorage.orders = JSON.stringify(orders);
        console.dir(localStorage.orders);
    })